from selenium import webdriver

#选择浏览器
from selenium.webdriver.chrome.service import Service


class UseBrowser:

    driver=None

    def __init__(self,browser_name='chrome',path='../../chromedriver.exe'):
        try:
            if browser_name.lower()=='chrome':  #把输入转化为小写
                driver_service=Service(executable_path=path)
                self.driver=webdriver.Chrome(service=driver_service)
                self.driver.maximize_window()
                self.driver.implicitly_wait(3)
                UseBrowser.driver=self.driver

            elif browser_name.lower()=='firefox':
                self.driver = webdriver.Firefox(path)
                self.driver.maximize_window()
                self.driver.implicitly_wait(3)
                UseBrowser.driver = self.driver


        except Exception as e:
            print('browser init error',e)

    @classmethod
    def browser_quit(cls):
        cls.driver.quit()

if __name__ == '__main__':
    use=UseBrowser()